import { request } from 'umi';

export async function loadSysName() {
  return request<string>('/api/sysname');
}

export async function getRoutes() {
  return request('/api/Routes/All');
}
export async function getMenu() {
  return request<API.SysInfo>('/api/restricted/Menu/All');
}
export async function getTask() {
  return request<API.FlowDoing>('/api/restricted/FlowDoingSum/All');
}
export async function menuTreeNodeFetch() {
  return request(`/api/restricted/Menu/TreeNode`);
}

export async function menuUserTreeNodeFetch(userStr: string) {
  const data = new FormData();
  data.append('UserPerms', userStr);
  return request(`/api/restricted/Menu/TreeNode/User`, {
    method: 'POST',
    body: data,
  });
}
/**获取角色权限 */
export async function CheckedRolePermsFetch(roleID: number) {
  return request(`/api/restricted/Menu/CheckedRole/perms/${roleID}`);
}
/**获取角色员工 */
export async function CheckedRoleUsersFetch(roleID: number) {
  return request(`/api/restricted/Menu/CheckedRole/users/${roleID}`);
}
/**获取员工权限 */
export async function CheckedUserPermsFetch(userID: number) {
  return request(`/api/restricted/Menu/CheckedUser/perms/${userID}`);
}
/**获取员工角色 */
export async function CheckedUserRolesFetch(userID: number) {
  return request(`/api/restricted/Menu/CheckedUser/roles/${userID}`);
}
/**角色权限设置 */
export async function rolePermsSave(
  roleID: number,
  permTreeCheckedKeys: string[],
  userTreeCheckedKeys: string[],
) {
  const data = new FormData();
  data.append('RolePerms', JSON.stringify(permTreeCheckedKeys));
  data.append('RoleUsers', JSON.stringify(userTreeCheckedKeys));
  return request(`/api/restricted/Menu/RolePerms/${roleID}`, {
    method: 'POST',
    body: data,
  });
}
/**用户权限设置 */
export async function userPermsSave(
  userID: number,
  permUserCheckedKeys: string[],
  roleTreeCheckedKeys: string[],
) {
  const data = new FormData();
  data.append('UserPerms', JSON.stringify(permUserCheckedKeys));
  data.append('UserRoles', JSON.stringify(roleTreeCheckedKeys));
  return request(`/api/restricted/Menu/UserPerms/${userID}`, {
    method: 'POST',
    body: data,
  });
}
